﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using hello.csharp.common.Interfaces;
using hello.csharp.common.Interfaces.Storages;
using hello.csharp.domain;
using hello.csharp.storage.Db;
using hello.csharp.storage.Db.Mongo;
using MongoDB.Driver;
using SortDirection = hello.csharp.common.Enums.SortDirection;

namespace hello.csharp.storage
{
    public class ProductStorageRead : MongoStorageBase, IProductStorageRead
    {
        private readonly IMongoCollection<Product> _collection;

        public ProductStorageRead(IDbManager dbManager)
            : base(dbManager)
        {
            _collection = _Database.GetCollection<Product>(nameof(Product));
        }

        #region Implementation of IStorageRead<out Product,in string>

        /// <summary>
        /// 当前实现面向的数据表表名
        /// </summary>
        public string TableName { get; } = $"{nameof(Product)}s";

        /// <summary>
        /// 分页查询方法
        /// </summary>
        /// <param name="pageNumber">当前页码。从0开始。</param>
        /// <param name="pageSize">每页的数据数量。</param>
        /// <param name="direction">查询数据时的排序方向。</param>
        /// <param name="skipDeleteTag">是否跳过打上删除标记的记录，默认(当false时)有删除标记的记录不包含在结果中</param>
        /// <returns>当前页的数据集合</returns>
        public async Task<IEnumerable<Product>> PageAsync(uint pageNumber, uint pageSize, SortDirection direction, bool skipDeleteTag = false)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 根据指定的ID获取指定的记录并转换为对象
        /// </summary>
        /// <param name="id">指定的ID</param>
        /// <param name="skipDeleteTag">是否跳过打上删除标记的记录，默认(当false时)有删除标记的记录不包含在结果中</param>
        /// <returns></returns>
        public async Task<Product> FindOneByIdAsync(string id, bool skipDeleteTag = false)
        {
            var result = await _collection.FindAsync(product => product.Id == id);
            return result.First();
        }

        /// <summary>
        /// 指定ID的记录是否存在
        /// </summary>
        /// <param name="id">指定的记录ID</param>
        /// <param name="skipDeleteTag">是否跳过打上删除标记的记录，默认(当false时)有删除标记的记录不包含在结果中</param>
        /// <returns>记录是否存在，true时存在指定ID的记录，false反之。</returns>
        public async Task<bool> ExistAsync(string id, bool skipDeleteTag = false)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 查询记录的数据记录统计数量
        /// </summary>
        /// <param name="skipDeleteTag">是否跳过打上删除标记的记录，默认(当false时)有删除标记的记录不包含在结果中</param>
        /// <returns>数量</returns>
        public async Task<uint> CountAsync(bool skipDeleteTag = false)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
